var default_uri = "flow.php" // DEFAULT URL
function gotourl(uri) {
    sendRequest(uri);
}

function actionthis(params) {
//	alert(params);
	sendRequest(default_uri, params);
}

// ASYNCRONIOUS REQUEST
function sendThis(params) {
	sendRequest(default_uri,params);
}

// SYNCRONIOUS REQUEST
function sendThisWait(params) {
	sendRequest(default_uri,params, false);
}

// FORM PROCCESING RELATED
function processForm(form) {
	var forma = document.forms[form];
	forma.submit();
	/*	
	var params = "";
	for (i=0;i<forma.length;i++) {
	  params += forma[i].name + "=" + forma[i].value + "&";
	}
	sendThisWait(params);
	*/
}


function isEnterKey(e) {
    key = (document.all) ? e.keyCode : e.which;
    return (key == 13);
}
function showdiv() {
    obj = document.getElementById("progressdiv");
    if (obj!=null)
        obj.style.display = "";
}

function hidediv() {
    obj = document.getElementById("progressdiv");
    if (obj!=null)
        obj.style.display = "none";
}

function processBy(text, form) {
    document.forms[form]['action'].value = text;
    process(form);
}


function process(form) {
    startProcess("Guardando");
	document.forms[form].submit();
}


function validateEmpty(ele, text) {
	obj = document.getElementById(ele);
	if (trim(obj.value)=="") {
		alert("El campo "+text+" es requerido");
		return false;
	}
	return true;
}

function trim(trim_value){
	if(trim_value.length < 1){
		return "";
	}
	trim_value = rtrim(trim_value);
	trim_value = ltrim(trim_value);
	if(trim_value==""){
		return "";
	}	else{
		return trim_value;
	}
}

function rtrim(valor){
	var w_space = String.fromCharCode(32);
	var v_length = valor.length;
	var strTemp = "";
	if(v_length < 0){
		return "";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		if(valor.charAt(iTemp) == w_space){
		}	else{
			strTemp = valor.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;

} //End Function

function ltrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}	else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function addFileInput( elem ) {
		if ( false != elem )
		{
			filepath = elem.value.split("\\");
			filename = filepath[filepath.length-1];
			extensionpath = filename.split(".");
			extension = extensionpath[extensionpath.length-1];
			$(elem).hide();
			$("#file_list").append("<li style='display:none'>"+filename+" <a href='javascript:;' onclick='delFile(this,"+($("#file_list li").size()+1)+")' style='color:red'>[x]</small></a></li>\n");

			$("#file_list li:last").slideDown("slow");
		}
		$("#file_inputs").append('<input name="file['+($("#file_list li").size()+1)+']" type="file" id="file['+($("#file_list li").size()+1)+']" size="20" onChange="addFileInput(this);">\n');

}

function delFile ( el, file )
{

    var cf = document.getElementById('currentFiles['+(file-1)+']');
    if (cf!=null)
        cf.value="";

	$(el.parentNode).remove();
	$("#file["+file+"]").remove();
}